package br.com.fogas.medicao.custom;

import br.com.fogas.medicao.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class CustomViewPager extends ViewPager {

	private boolean swipeable;
	
	public CustomViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomViewPager);
	    try {
	        swipeable = a.getBoolean(R.styleable.CustomViewPager_swipeable, true);
	    } finally {
	        a.recycle();
	    }
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (this.swipeable) {
			return super.onTouchEvent(event);
		}

		return false;
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent event) {
		if (this.swipeable) {
			return super.onInterceptTouchEvent(event);
		}

		return false;
	}

	public void setPagingEnabled(boolean enabled) {
		this.swipeable = enabled;
	}
}
